import 'dart:io';

import 'package:dio/dio.dart';

import 'dart:async';
import 'Helper.dart';
import 'uidata.dart';
class FileHelper {

//返回 路径
  static Future<String> DownLoad(String url, String fileName) async {
    
    var dio2=new Dio();
    dio2.options.contentType="application/x-www-form-urlencoded";

    String path =Helper.GetRandPath()+"_"+fileName;

    var response = await dio2.download(url, path);
    print(response.data.toString());
    
    return path;
  }

  static Future<String> DownLoad2(String url, String fileName) async {
    
    var dio2=new Dio();
   dio2.options.contentType="application/x-www-form-urlencoded";

    String path =fileName;

    var response = await dio2.download(url, path);
    print(response.data.toString());
    
    return path;
  }



  static Future<bool> DownLoadSavePath(String url, String path) async {
    
    var dio2=new Dio();
    dio2.options.contentType="application/x-www-form-urlencoded";

    var response = await dio2.download(url, path);
    print(response.data.toString());
    if(response.statusCode==200)
    return true;
    return false;
  }

///可用
  static Future<String> UpLoad(File f1) async {
    Dio dio = new Dio();
    var formData = new FormData.fromMap({
      "name": "wendux",
      "age": 25,
      //"file": f1,
      "file": await MultipartFile.fromFile(f1.path,filename: "upload.txt")
    });
    var response =
        await dio.post(UIData.fileUploadServer, data: formData);

    if (response.statusCode == HttpStatus.ok) {
      return response.data.toString();
    } else {
      return "";
    }
  }


  static Future<String> UpLoad2(String f1) async {
    Dio dio = new Dio();
    var formData = new FormData.fromMap({
      "name": "wendux",
      "age": 25,
      //"file": f1,
      "file": await MultipartFile.fromFile(f1,filename: "upload.txt")
    });
    var response =
        await dio.post(UIData.fileUploadServer, data: formData);

    if (response.statusCode == HttpStatus.ok) {
      return response.data.toString();
    } else {
      return "";
    }
  }

}
